package org.westboy.controller;

import de.felixroske.jfxsupport.FXMLController;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.web.HTMLEditor;
import org.springframework.beans.factory.annotation.Autowired;
import org.westboy.common.base.BaseController;
import org.westboy.common.base.OrderContext;
import org.westboy.common.util.AppUtil;
import org.westboy.common.util.HtmlKit;
import org.westboy.mybatis.model.MallbuilderProductOrder;
import org.westboy.service.OrderService;

@FXMLController
public class NoteController extends BaseController{

    @FXML
    private Label orderId;

    @FXML
    private Label price;

    @FXML
    private Label consignee;

    @FXML
    private Label createTime;

    @FXML
    private Label dec;

    @FXML
    private Label orderNote;

    @FXML
    private HTMLEditor content;


    @Autowired
    private OrderContext orderContext;


    @Autowired
    private OrderService orderService;


    @FXML
    private void doUpdate(){
        String noteHtmlTxt = HtmlKit.getText(content.getHtmlText());
        MallbuilderProductOrder order = new MallbuilderProductOrder();
        order.setId(orderContext.getOrder().getId());
        order.setOrderId(orderContext.getOrder().getOrderId());
        order.setOrderNote(noteHtmlTxt);
        if(orderService.update(order)>0){
            orderContext.getOrder().setOrderNote(noteHtmlTxt);
            AppUtil.showSuccessAlert("保存备注成功！");
        }else{
            AppUtil.showErrorAlert("添加备注失败！");
        }

    }

    @Override
    protected void initialize() {
        orderId.textProperty().bind(orderContext.getOrder().orderIdProperty());
        price.textProperty().bind(orderContext.getOrder().priceProperty().asString());
        consignee.textProperty().bind(orderContext.getOrder().consigneeProperty());
        createTime.textProperty().bind(orderContext.getOrder().createTimeProperty());
        dec.textProperty().bind(orderContext.getOrder().desProperty());
        orderNote.textProperty().bind(orderContext.getOrder().orderNoteProperty());

    }
}
